package com.prs.crm.action.sys;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.sys.ForumAnonymity;
import com.prs.crm.service.sys.ForumAnonymityService;

public class ForumAnonymityAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private PaginationSupport pagination;
	private ForumAnonymity forumAnonymity;
	private ForumAnonymityService forumAnonymityService;
	private String inser;
	public String getInser() {
		return inser;
	}
	public void setInser(String inser) {
		this.inser = inser;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public ForumAnonymity getForumAnonymity() {
		return forumAnonymity;
	}
	public void setForumAnonymity(ForumAnonymity forumAnonymity) {
		this.forumAnonymity = forumAnonymity;
	}
	public ForumAnonymityService getForumAnonymityService() {
		return forumAnonymityService;
	}
	public void setForumAnonymityService(ForumAnonymityService forumAnonymityService) {
		this.forumAnonymityService = forumAnonymityService;
	}
	@Action("listForumAnonymity")
	public String listForumAnonymity(){
		List<ForumAnonymity> forum=this.getForumAnonymityService().getAllForumAnonymitie();
		if (forum.size()<=0) {
			ForumAnonymity fa=new ForumAnonymity();
			fa.setSerCode("fa01");
			fa.setState(0);
			this.getForumAnonymityService().save(fa);
		}
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(ForumAnonymity.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getForumAnonymityService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	@Action(value = "saveForumAnonymity", results = {
			@Result(name = "success", type = "redirect", location = "listForumAnonymity"),
			@Result(name = "error", type = "chain", location = "listForumAnonymity")})
	public String saveForumAnonymity(){
		forumAnonymity.setState(0);
		this.getForumAnonymityService().submit(forumAnonymity);
		return SUCCESS;
	}
	@Action(value = "saveForumAnonymitys", results = {
			@Result(name = "success", type = "redirect", location = "listForumAnonymity"),
			@Result(name = "error", type = "chain", location = "listForumAnonymity")})
	public String saveForumAnonymitys(){
		forumAnonymity.setState(1);
		this.getForumAnonymityService().submit(forumAnonymity);
		return SUCCESS;
	}
}
